# by lyzh 2015
#

# Guard against multiple inclusion, which e.g. leads to multiple calls to add_definition() #12987
if (__SYLIXOS_TOOLCHAIN_FILE)
  return()
endif()
set(__SYLIXOS_TOOLCHAIN_FILE TRUE)

##################################################
## setup building info
##################################################

# where to find the compiler
set(CROSS_TOOL_FULL /home/lyzh/gcc-sylixos/bin CACHE PATH "where to find the compiler" )

# where is SylixOS source 
set(SYLIXOS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE PATH "where is SylixOS source " )

# where is SylixOS building directory
set(SYLIXOS_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}  CACHE PATH "where is SylixOS building directory" )

set(CMAKE_SYSROOT /home/lyzh/projects/sylixos/workspace/libsylixos/sysroot CACHE PATH "where sysroot " )

# specify a path on the host to install to
set(CMAKE_STAGING_PREFIX /home/lyzh/projects/sylixos/workspace/libsylixos/sysroot)
set(CMAKE_INSTALL_PREFIX /home/lyzh/projects/sylixos/workspace/libsylixos/sysroot)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

# some options
#add_compile_options( -mfloat-abi=softfp -mfpu=vfpv3 -mcpu=arm920t )
add_compile_options( -mfloat-abi=softfp -mfpu=vfpv3 -mcpu=arm920t )

# setup compiler
include (CMakeForceCompiler)
# assembler
macro(CMAKE_FORCE_ASM_COMPILER compiler id)
  set(CMAKE_ASM_COMPILER "${compiler}")
  set(CMAKE_ASM_COMPILER_ID_RUN TRUE)
  set(CMAKE_ASM_COMPILER_ID ${id})
  set(CMAKE_ASM_COMPILER_FORCED TRUE)

  # Set old compiler id variables.
  if("${CMAKE_ASM_COMPILER_ID}" MATCHES "GNU")
    set(CMAKE_COMPILER_IS_GNUCC 1)
  endif()
endmacro()

# tool may need full path
set(CMAKE_SYSTEM_NAME UNIX)
CMAKE_FORCE_C_COMPILER(${CROSS_TOOL_FULL}/arm-none-eabi-gcc GNU)
CMAKE_FORCE_CXX_COMPILER (${CROSS_TOOL_FULL}/arm-none-eabi-g++ GNU)
CMAKE_FORCE_ASM_COMPILER (${CROSS_TOOL_FULL}/arm-none-eabi-g++ GNU)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_AR ${CROSS_TOOL_FULL}/arm-none-eabi-ar)
set(CMAKE_LINK ${CROSS_TOOL_FULL}/arm-none-eabi-gcc)
set(CMAKE_RANLIB ${CROSS_TOOL_FULL}/arm-none-eabi-ranlib)
set(SYLIXOS_OBJCOPY ${CROSS_TOOL_FULL}/arm-none-eabi-objcopy)

set(CMAKE_AR ${CROSS_TOOL_FULL}/arm-none-eabi-ar)
set(CMAKE_RANLIB ${CROSS_TOOL_FULL}/arm-none-eabi-ranlib)

#set(CMAKE_VERBOSE_MAKEFILE TRUE)


# always include sylixos.cmake.
include(${SYLIXOS_SOURCE_DIR}/sylixos.cmake)

